package edu.ads.bookloan

class StudentResultStrategy implements ResultStrategy {

	def currentUser

	@Override
	public Object getResult(def params) {
		def loanHistoryList
		def criteria = LoanHistory.createCriteria()
		Person person = Person.get(currentUser.id)
		//loanHistoryList = LoanHistory.findAll("from LoanHistory a where a.dateReturned is null and a.person.id = ?  ",[])
		loanHistoryList = criteria.list(max: params.max, offset: params.offset){
			isNull('dateReturned')
			eq('person',person)
			!params.sort ? order('dateCreated','asc') : order(params.sort, params.order)
		}
		return loanHistoryList
	}
}
